#include "getfile.h"


void GetFile(int peerfd,char* filename)
{
    //1.先接收文件长度
    size_t filelength = 0;
    recvCircle(peerfd,&filelength,8);

    //2.创建文件。不判断文件是否存在
    int fd = open(filename,O_CREAT | O_RDWR | O_TRUNC,0664);

    //3.接收文件.没有判断是否断开连接
    char recvbuf[1024] = {0};
    while(filelength > 0)
    {
        memset(&recvbuf,0,1024);
        int len = 0;
        recvCircle(peerfd,&len,4);
        recvCircle(peerfd,recvbuf,len);
        write(fd,recvbuf,len);
    }
    close(fd);
}

